package model;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.util.ArrayList;

public class ArrayStack<E> extends AdapterStack<E> implements Prediction<E>{
	
	int size = 1;
	private ArrayList<Integer> yCo; 
	private boolean predictPressed = false;
	
	public void setSize(int i){
		size = i;
	}
	public int getSize(){
		return size;
	}
	
	public ArrayList<Integer> getYCo(){
		return yCo;
	}
	
	public void paint(Graphics g) {

	     int x = 400;
	     int y = 550;
	     int h = 60;
	     int w = 60;
	     
	     g.setFont(new Font("",0,15));
		 g.drawString("Array Stack Mode", 10, 20);
	     
		 g.setFont(new Font("",0,20));
		 g.drawString("Bottom", x, y+h+30);
		 
	     for(int i = 0; i < size; i++){
	         g.drawRect(x, y, w, h);
	         g.drawString(String.valueOf(i),x+w+10,y+40);
	         y = y - h -10;
	     }
	     y = 550;
		 g.setFont(new Font("",0,50));
		 FontMetrics fm = null;
		 fm = g.getFontMetrics();
		
		if(!S.isEmpty()){
			yCo  = new ArrayList<Integer>();

		     g.setColor(new Color(0,0,0,200));
		     		     	
			     for(int i=size(); i != 0; i--){
			    	 yCo.add(y);
			    	 String s = (String) S.get(i-1);
			         g.drawString(s,(((w - fm.charWidth(s.charAt(0)))/2)+x), (y + 47 ));
			         y = y - h -10;        
			     }
			    	     
				  if(predictPressed==true){
					  yCo.add(y);			  
				  }
				  
				predictPressed =false;
		}	  
		
	     g.setFont(new Font("",0,20));
	     if(size() < size){
	    	 g.drawString("Top", x-50, y+h/2);
	     }
	     else{
	    	 g.drawString("Full", x+12, y+h);	 
	     }
	     
	}
	@Override
	public boolean predictAdd(int guess) {
		if(guess == S.size()){
			return true;
		}
		else{
			return false;
		}
	}
	@Override
	public boolean predictRemove(int guess) {
		if(guess == (S.size()-1)){
			return true;
		}
		else{
		return false;
		}
	}
	@Override
	public void setPressed(boolean b) {
		predictPressed=b;
	}

}
